// 例子42

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
        this.getX = this.getX.bind(this); // 绑定this，保证方法单独调用不会出错
    }

    getX() {
        return this.x;
    }

    getY() {
        return this.y;
    }
}

let p = new Point(1, 2);
const {
    getX,
    getY
} = p;
console.log(getX()); // 1
getY(); // Uncaught TypeError: Cannot read property 'y' of undefined